/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package globaltradutorap;

import java.awt.event.ActionListener;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.ws.WebServiceRef;

/**
 *
 * @author Pedro
 */
public class Interface extends javax.swing.JFrame {
    @WebServiceRef(wsdlLocation = "META-INF/wsdl/localhost_8080/gtWebService/gtWebService.wsdl")
    private static GtWebService_Service service;

    /**
     * Creates new form Interface
     */
    
    public Interface() throws FileNotFoundException_Exception {
        initComponents();
        this.setResizable(false);
        Texto_saida.setEditable(false);
        Botao_traduzir.setEnabled(false);
        Idioma_entrada.setEnabled(false);
        Idioma_saida.setEnabled(false);
 
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    /*@SuppressWarnings("unchecked")*/
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        Texto_entrada = new javax.swing.JTextArea();
        Idioma_entrada = new javax.swing.JComboBox();
        Idioma_saida = new javax.swing.JComboBox();
        Texto_saida = new javax.swing.JTextField();
        Botao_traduzir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Global Tradutor");

        Texto_entrada.setColumns(20);
        Texto_entrada.setRows(5);
        Texto_entrada.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                Texto_entradaKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(Texto_entrada);

        Idioma_entrada.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Idioma Entrada" }));
        Idioma_entrada.setToolTipText("");
        Idioma_entrada.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                Idioma_entradaItemStateChanged(evt);
            }
        });

        Idioma_saida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Idioma Saida" }));
        Idioma_saida.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                Idioma_saidaItemStateChanged(evt);
            }
        });

        Botao_traduzir.setText("Traduzir");
        Botao_traduzir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Botao_traduzirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Idioma_saida, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Idioma_entrada, 0, 197, Short.MAX_VALUE))
                .addGap(24, 24, 24)
                .addComponent(Texto_saida, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(Botao_traduzir, javax.swing.GroupLayout.PREFERRED_SIZE, 568, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 42, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(Idioma_entrada, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Idioma_saida, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(53, 53, 53))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Texto_saida, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(43, 43, 43)))
                .addComponent(Botao_traduzir, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(64, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Texto_entradaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Texto_entradaKeyReleased
        // TODO add your handling code here:
         if(Texto_entrada.getText().equals("") && Texto_entrada.getText().length()==0){
            
            Idioma_entrada.setEnabled(false);
            Idioma_entrada.setSelectedIndex(0);
            
            Idioma_saida.setSelectedIndex(0);
            Idioma_saida.setEnabled(false);
           
            Botao_traduzir.setEnabled(false);
            
        }
        else
        {     
             try {
                 List<Object> Idioma = getIdiomaEntrada();
                 
                 for(int i=0;i<Idioma.size();i++){
                     Idioma_entrada.addItem(Idioma.get(i).toString());
                 }
                 
                 for(int i=0;i<Idioma.size();i++){
                     Idioma_saida.addItem(Idioma.get(i).toString());
                 }
                 
                 Idioma_entrada.setEnabled(true);
             } catch (FileNotFoundException_Exception ex) {
                 Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
             }
        }
         
    }//GEN-LAST:event_Texto_entradaKeyReleased

    private void Idioma_entradaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_Idioma_entradaItemStateChanged
  
        if(Idioma_entrada.getSelectedIndex()==0){
            
            Idioma_saida.setEnabled(false);
            Botao_traduzir.setEnabled(false);            
        }
        else{
            Idioma_saida.setEnabled(true);
        }        
    }//GEN-LAST:event_Idioma_entradaItemStateChanged

    private void Idioma_saidaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_Idioma_saidaItemStateChanged
        
        if(Idioma_saida.getSelectedIndex()==0){
            Botao_traduzir.setEnabled(false);
        }
        else{
                Botao_traduzir.setEnabled(true);
        }
    }//GEN-LAST:event_Idioma_saidaItemStateChanged

    private void Botao_traduzirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Botao_traduzirActionPerformed
        // TODO add your handling code here:
        String idioma_entrada = Idioma_entrada.getSelectedItem().toString();
        String idioma_saida = Idioma_saida.getSelectedItem().toString();
        String frase = Texto_entrada.getText();
        
        
    }//GEN-LAST:event_Botao_traduzirActionPerformed

  
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Interface().setVisible(true);
                } catch (FileNotFoundException_Exception ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Botao_traduzir;
    private javax.swing.JComboBox Idioma_entrada;
    private javax.swing.JComboBox Idioma_saida;
    private javax.swing.JTextArea Texto_entrada;
    private javax.swing.JTextField Texto_saida;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    private static java.util.List<java.lang.Object> getIdiomaEntrada() throws FileNotFoundException_Exception {
        // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe.
        // If the calling of port operations may lead to race condition some synchronization is required.
        globaltradutorap.GtWebService port = service.getGtWebServicePort();
        return port.getIdiomaEntrada();
    }
}
